/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DAL.ConnectUnit;
import DTO.DailyReport_DTO;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.HashSet;

/**
 *
 * @author Nguyen Phi Hung
 */
public class DailyReport_BLL {
    
    ConnectUnit connection;
    
    public DailyReport_BLL(){
        this.connection = DAL.DAL.getDAL();
    }
    
    /**
     * get list of DailyRepor form database with Condition and OrderBy
     * @param condition
     * @param OrderBy
     * @return
     * @throws Exception 
     */
    public HashSet<DailyReport_DTO> getDailyReports(String condition, String OrderBy) throws Exception{
        ResultSet result = this.connection.Select("DAILYREPORT", condition, OrderBy);
        HashSet<DailyReport_DTO> dailyreports = new HashSet<DailyReport_DTO>();
        while(result.next()){
            
        }
        return dailyreports;
    }
    
    /**
     * get list of DailyRepor form database with Condition
     * @param condition
     * @return
     * @throws Exception 
     */
    public HashSet<DailyReport_DTO> getDailyReports(String condition) throws Exception{
        return this.getDailyReports(condition, null);
    }
    
    /**
     * get list of DailyRepor from database
     * @return
     * @throws Exception 
     */
    public HashSet<DailyReport_DTO> getDailyReports() throws Exception{
        return this.getDailyReports(null, null);
    }
    
    /**
     * Get DailyReport by ReportID from database
     * @param ID
     * @return
     * @throws Exception 
     */
    public DailyReport_DTO getDailyReport_byReportID(String ID) throws Exception{
        HashSet<DailyReport_DTO> dailyreport = this.getDailyReports("ReportID='" +ID+ "'");
        if(dailyreport.size()>0)
            return dailyreport.toArray(new DailyReport_DTO[dailyreport.size()])[0];
        return null; 
    }
    
    /**
     * get DailyReport by Index
     * @param list
     * @param index
     * @return 
     */
    public DailyReport_DTO getDailyReportbyIndex(HashSet<DailyReport_DTO> list, int index){
        return (index >= list.size()) ? null : list.toArray(new DailyReport_DTO[list.size()])[index];
    }
    
    /**
     * Insert one DailyReport into database
     * @param info
     * @throws Exception 
     */
    public void Insert(DailyReport_DTO info) throws Exception{
        HashMap<String, Object> map = new HashMap<String, Object>();
        
        map.put("ReportID", info.getReportID());
        map.put("ReportingDate", info.getReportingDate());
        
        String[] arr = {"ReportID","ReportingDate"};
        this.connection.Insert("DAILYREPORT", map, arr);        
    }
    
    /**
     * Update a DailyReport in Database
     * @param info
     * @throws Exception 
     */
    public void Update(DailyReport_DTO info) throws Exception{
        HashMap<String, Object> map = new HashMap<String, Object>();
        
        map.put("ReportID", info.getReportID());
        map.put("ReportingDate", info.getReportingDate());
        
        this.connection.Update("DAILYREPORT", map, "ReportID="+ info.getReportID());  
    }
    
    /**
     * Delete a DailyReport in Database
     * @param info
     * @throws Exception 
     */
    public void Delete(DailyReport_DTO info) throws Exception{
        this.connection.Delete("DAILYREPORT", "ReportID="+ info.getReportID());
    }
}
